home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / IEEE / src / div0 / lattice / div0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  1.3 KB  |  70 lines

  1.  
  2. #include <exec/types.h>
  3. #include "setjmp.h"
  4.  
  5. #define    SIGDIV0    5
  6. #define SIGTRAPV        7
  7. #define SIGFPCP_DIVIDEBY0       50
  8. #define SIGFPCP_OVERFLOW        53
  9.  
  10. jmp_buf div0_buf;
  11.  
  12. #define LATTICE
  13. #ifdef LATTICE
  14. extern    long    MathIeeeDoubBasBase;
  15. #else
  16. long    MathIeeeDoubBasBase = 0;
  17. #endif
  18.  
  19. #define LONGJMPIT
  20.  
  21. void SigTrap0()
  22. {
  23.     printf("divide by zero caught\n");
  24.     longjmp(div0_buf, 1);
  25. }
  26.  
  27. DOUBLE    zero = 0.0;
  28. DOUBLE    one = 1.0;
  29. DOUBLE    result;
  30.  
  31. void main(argc,argv)
  32. {
  33.     printf(" Test Divide by zero handling\n");
  34.  
  35.     MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",0);
  36.  
  37.     if (!MathIeeeDoubBasBase)
  38.     {
  39.         printf(" could not open Mathieeedoubbas.library\n");
  40.         exit(-1);
  41.     }
  42.  
  43.     /* first set up Intercept routine */
  44.  
  45. #ifdef    LONGJMPIT
  46.     InterceptTrap(SIGDIV0, SigTrap0);    /* for 68000/68010 */
  47.     InterceptTrap(SIGFPCP_DIVIDEBY0, SigTrap0);    /* 68020 */
  48. #else /* ignore it */
  49.     InterceptTrap(SIGDIV0, -1);    /* for 68000/68010 */
  50.     InterceptTrap(SIGFPCP_DIVIDEBY0, -1);    /* 68020 */
  51. #endif
  52.  
  53.     if (setjmp(div0_buf)) goto caught_div0;
  54.  
  55.     result = one/zero;
  56.  
  57.     printf("H'mmm, no error? , oh well result=%lx,%lx\n",result);
  58.         goto exit;
  59.  
  60. caught_div0:
  61.     printf(" back in main program, and NO guru \n");
  62.  
  63. exit:
  64.     CloseLibrary(MathIeeeDoubBasBase);
  65. #ifdef LATTICE
  66.     MathIeeeDoubBasBase = 0;
  67. #endif
  68.     exit(0);
  69. }
  70.